﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include <QLineEdit>
#include <QMessageBox>
#include <QDebug>
#include <QTimer>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    auto res=connect(ui->lineEdit,&QLineEdit::textChanged,ui->label,&QLabel::setText,Qt::ConnectionType(Qt::AutoConnection|Qt::UniqueConnection));
    qDebug()<<res<<endl;
    connect(this,SIGNAL(signal(const QString &)),ui->lineEdit,SLOT(setText(const QString &)));

    pBtn=new QPushButton(this);
    pBtn->setGeometry(0,400,400,200);
    pBtn->setText("用自定义类型测试自定义的信号和槽");
    connect(pBtn,SIGNAL(clicked()),this,SLOT(sentSIGNAL()));
    connect(this,SIGNAL(my_signal(People&)),this,SLOT(slotFunc(People&)));
}

MainWindow::~MainWindow()
{
    delete ui;
}


//void MainWindow::on_lineEdit_textChanged(const QString &arg1)
//{
//    ui->label->setText(arg1);
//}

void MainWindow::on_pushButton_clicked()
{
    QMessageBox::information(this,"人才","人才");
    emit ui->lineEdit->textChanged("哈哈哈");
    emit this->signal("你好大哥");
}

void MainWindow::sentSIGNAL()
{
    qDebug()<<"人才";
    People p;
    p.setAge(21);
    p.setName("姚国林");
    emit my_signal(p);
    disconnect(pBtn,SIGNAL(clicked()),this,SLOT(sentSIGNAL()));
}

void MainWindow::slotFunc(People &p)
{
    QMessageBox::information(this,"提示","姓名:"+p.getName()+" 年龄: "+QString::number(p.getAge()));
}

People::People()
{
    this->age=0;
    this->name="";
}

void People::setName(QString name)
{
    this->name=name;
}

void People::setAge(int age)
{
    this->age=age;
}

QString People::getName() const
{
    return this->name;
}

int People::getAge() const
{
    return this->age;
}
